<script setup>
import { ref, computed } from 'vue';

const timeRangeIndex = ref(0);
const timeRangeOptions = ["近一个月", "近三个月", "近一年"];

const allHolidayData = ref([
  {
    year: 2024,
    startTime: "2024-11-16 00:00:00",
    endTime: "2024-11-16 00:00:00",
    duration: 26,
  },
]);

const holidayData = computed(() => {
  return allHolidayData.value.filter(item => item.year === 2024);
});

const onTimeRangeChange = (e) => {
  timeRangeIndex.value = e.detail.value;
  console.log(`选择了：${timeRangeOptions[timeRangeIndex.value]}`);
};
</script>

<template>
  <view class="holiday-page">
<!--时间-->
    <view class="top-right-container">

      <view class="selector-container">

        <picker
            @change="onTimeRangeChange"
            :value="timeRangeIndex"
            :range="timeRangeOptions"
        >

          <view class="picker-view">
            {{ timeRangeOptions[timeRangeIndex] }}

            <image src="/static/arrow-down.png" class="arrow-icon" />

          </view>

        </picker>

      </view>

    </view>

    <view class="holiday-list">
<!--数据表-->
      <view
          class="holiday-item"
          v-for="(item, index) in holidayData"
          :key="index"
      >

        <view class="item-header">

          <image src="/static/home-icon.png" class="item-icon" />
          <image src="/static/image/bz@2x.png" class="bz-icon" />
          <text class="item-title">{{ item.year }}年春节放假</text>

        </view>

        <view class="item-info">

          <text>假期开始时间：{{ item.startTime }}</text>
          <text>假期结束时间：{{ item.endTime }}</text>
          <text>时长：{{ item.duration }}天</text>

        </view>

      </view>

    </view>

  </view>
</template>

<style scoped>
.holiday-page {
  padding: 16px;
  background-color: #f5f7fa;
  position: relative;
  min-height: 100vh;
}

.top-right-container {
  position: absolute;
  top: 16px;
  right: 16px;
}

.selector-container {
  display: inline-block;
}

.picker-view {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid #e5e7eb;
  font-size: 12px;
  white-space: nowrap;
}

.arrow-icon {
  width: 10px;
  height: 10px;
  margin-left: 4px;
}

.holiday-list {
  margin-top: 50px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.holiday-item {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: rgba(255, 255, 255, 0.85);
  position: relative;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.item-header, .item-info {
  position: relative;
  z-index: 2;
}

.item-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
}

.item-icon {
  width: 24px;
  height: 24px;
}

.bz-icon {
  width: 22px;
  height: 22px;
}

.item-title {
  width: 119px;
  height: 22px;
  font-weight: 500;
  font-size: 16px;
  color: #212121;
}

.item-info {
  display: flex;
  flex-direction: column;
  width: 203px;
  height: 66px;
  font-weight: 400;
  font-size: 12px;
  color: #5D5E5D;
  line-height: 22px;
}
</style>